//
//  oldKeyChain.m
//  laonianbang
//
//  Created by 勇拓 李 on 17/10/29.
//  Copyright © 2017年 zaiyou. All rights reserved.
//

#import "oldKeyChain.h"
#import <AdSupport/AdSupport.h>
#import "oldKeyChainManager.h"

@implementation oldKeyChain

+(NSString *)getIDFA
{
    const char *strRet;
    
    NSString *identifier = [[NSBundle mainBundle] bundleIdentifier];
    NSString *keyName = [[NSString stringWithFormat:@"%@.adfa.name",identifier] init];
    NSString *keyValue = [[NSString stringWithFormat:@"%@.adfa.value",identifier] init];
    
    NSMutableDictionary *KeyNameValue = (NSMutableDictionary *)[oldKeyChainManager load:keyName];
    NSString *ValueADFA= [KeyNameValue objectForKey:keyValue];
    
    if(ValueADFA)
    {
        strRet = [[ValueADFA uppercaseString] UTF8String];
    }
    else
    {
        NSString *adId =[[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
        //NSLog(@"adId:  %@",adId);
        strRet = [[adId uppercaseString] UTF8String];
        
        NSMutableDictionary *usernamepasswordKVPairs = [NSMutableDictionary dictionary];
        [usernamepasswordKVPairs setObject:adId forKey:keyValue];
        [oldKeyChainManager save:keyName data:usernamepasswordKVPairs];
    }
    
    NSString *ret =  [[NSString alloc] initWithUTF8String:strRet];
    
    return ret;
}

@end
